package com.example.module_home.adapter

import android.view.View
import android.widget.ImageView
import androidx.activity.viewModels
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.viewModelFactory
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.module_home.R
import com.example.module_home.entity.MyHouseEntity
import com.example.module_home.vm.HouseViewModel

class HouseAreaAdapter(vm:HouseViewModel):BaseQuickAdapter<MyHouseEntity,BaseViewHolder>(R.layout.item_areahouse){
    lateinit var houseAdapter:HouseAdapter
    lateinit var vm:HouseViewModel
    init {
        this.vm=vm
    }
    override fun convert(holder: BaseViewHolder, item: MyHouseEntity) {
        holder.setText(R.id.area_tv1,"${item.dong}栋")
        holder.setText(R.id.area_tv2,"${item.area}㎡")
        
        houseAdapter= HouseAdapter(vm)
        houseAdapter.addData(item.list)
        val rv = holder.getView<RecyclerView>(R.id.house_area_rv)
        rv.adapter=houseAdapter

        val iv = holder.getView<ImageView>(R.id.area_iv)
        iv.setOnClickListener {
            if (rv.visibility==View.GONE){
                rv.visibility=View.VISIBLE
                iv.setImageResource(R.drawable.baseline_expand_xia_more_24)
            }else{
                rv.visibility=View.GONE
                iv.setImageResource(R.drawable.baseline_expand_shang_less_24)
            }
        }
    }
}